
// import { homeList } from '@/services'
import {
    homeList, homeListTitle, homeClassNav, gettopNoticeList,
    gettopNoticeDetail, getswiper
} from '@/services'


const state = {
    TopNoticeList: [],
    NoticeDetail: {},
    swiperList: [],
    list: [],
    listTitle: [],
    lastedProdPagelist: []
};
// “getters:类似是Vuex中的计算属性,也具有缓存功能:
// 如果state中的数据得到了改变,那么getters中的属性的值也会发生改变,
// 如果state的值没有发生任何变化,那么getters中的属性,的值就不会发生改变”
const getters = {};

const mutations = {
    swiperData(state, payload) {
        console.log(payload);
        for (let key in payload) {
            state[key] = payload[key];
        }
    },

    get_list(state, payload) {
        for (let key in payload) {
            state[key] = payload[key];
        }
    },
    get_homeListTitle(state, payload) {
        state.listTitle = JSON.parse(JSON.stringify(payload.listTitle))
    },
    get_homeClassNav(state, payload) {
        console.log(payload, 'nav');
        state.lastedProdPagelist = payload.lastedProdPagelist
    },

};

const actions = {
    // 轮播
    async getswiper({ commit }, payload) {
        let result = await getswiper(payload);
        console.log(result, '请求到了');
        if (result) {
            commit('swiperData', { swiperList: result });
        }
    },

    async gettopNoticeList({ commit }, payload) {
        let result = await gettopNoticeList();
        console.log(result, '上下----');
        if (result) {
            commit("swiperData", { TopNoticeList: result });
        }
        console.log(state.TopNoticeList);
    },

    async gettopNoticeDetail({ commit }, payload) {
        let result = await gettopNoticeDetail(payload);

        if (result) {
            commit("swiperData", { NoticeDetail: result });
        }
        console.log(state.NoticeDetail);
    },

    // 列表
    async homeList({ commit }, payload) {
        let result = await homeList();
        if (result) {
            commit('get_list', { list: result.records });
        }
    },
    // 列表标题
    async homeListTitle({ commit }, payload) {
        let result = await homeListTitle()
        console.log(result, '=======');
        if (result) {
            commit('get_homeListTitle', { listTitle: result })
        }
    },
    //    推荐导航、
    async homeClassNav({ commit }, payload) {
        let result = await homeClassNav(payload)
        console.log(result.records, 'nav数据');
        if (result) {
            commit('get_homeClassNav', { lastedProdPagelist: result.records })
        }
    }
};

export default {
    namespaced: true,
    modules: {},
    state,
    getters,
    mutations,
    actions,
}